<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"sekla.cn","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"valine","storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="Crypto++实现常用加密算法加密算法实现部分：通过Crypto++库对常用算法进行实现与再封装。 源代码：https:&#x2F;&#x2F;github.com&#x2F;ShenTiao&#x2F;cryptoSchoolProject.git">
<meta property="og:type" content="article">
<meta property="og:title" content="Crypto++&amp;pybind11&amp;pyqt5实现简易加密软件">
<meta property="og:url" content="http://sekla.cn/2022/01/08/crypto-project/index.html">
<meta property="og:site_name" content="Sekla&#39;s Blog">
<meta property="og:description" content="Crypto++实现常用加密算法加密算法实现部分：通过Crypto++库对常用算法进行实现与再封装。 源代码：https:&#x2F;&#x2F;github.com&#x2F;ShenTiao&#x2F;cryptoSchoolProject.git">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s2.loli.net/2021/12/06/2R7Lig8oeplqjAs.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/06/g8PNbseVpDaEqF4.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/06/o93iwY4RUHyqS5v.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/06/ILkiNmDwXy7RZPY.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/06/ZQMfBw9J1kzj8XK.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/07/Ou7JMUXEsKTpZ8I.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/07/12ETvCjLok9aRbn.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/08/VfpBGEvOU4dyZtr.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/08/89unBC1RcSaLhyg.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/07/12ETvCjLok9aRbn.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/13/9WrERUSM4ZjBQLl.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/29/twzLFS8pVYCKmfy.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/22/Ccnq5ymxolKSWwe.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/31/Xz3UL47ZMiJmhpF.png">
<meta property="og:image" content="https://s2.loli.net/2022/01/08/Goa2fYiTd9VLr7K.png">
<meta property="og:image" content="https://s2.loli.net/2022/01/08/KvMFrj5aD3lgE46.png">
<meta property="og:image" content="https://s2.loli.net/2022/01/08/IwQj7EuyFoqTrfU.png">
<meta property="article:published_time" content="2022-01-08T08:30:00.000Z">
<meta property="article:modified_time" content="2022-01-13T14:45:06.973Z">
<meta property="article:author" content="Sekla">
<meta property="article:tag" content="C++">
<meta property="article:tag" content="Python">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s2.loli.net/2021/12/06/2R7Lig8oeplqjAs.png">

<link rel="canonical" href="http://sekla.cn/2022/01/08/crypto-project/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Crypto++&pybind11&pyqt5实现简易加密软件 | Sekla's Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

  <script type="text/javascript" src="/js/my_js/clicklove.js"></script>
<!-- hexo injector head_end start -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-math@4.0.0/dist/style.css">
<!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Sekla's Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Keep Learning Keep Doing</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">14</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">23</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">100</span></a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://sekla.cn/2022/01/08/crypto-project/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Sekla">
      <meta itemprop="description" content="Sekla">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Sekla's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Crypto++&pybind11&pyqt5实现简易加密软件
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-01-08 16:30:00" itemprop="dateCreated datePublished" datetime="2022-01-08T16:30:00+08:00">2022-01-08</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-01-13 22:45:06" itemprop="dateModified" datetime="2022-01-13T22:45:06+08:00">2022-01-13</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%AF%86%E7%A0%81%E5%AD%A6/" itemprop="url" rel="index"><span itemprop="name">密码学</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>10k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>9 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="Crypto-实现常用加密算法"><a href="#Crypto-实现常用加密算法" class="headerlink" title="Crypto++实现常用加密算法"></a>Crypto++实现常用加密算法</h1><p>加密算法实现部分：通过Crypto++库对常用算法进行实现与再封装。</p>
<p>源代码：<a target="_blank" rel="noopener" href="https://github.com/ShenTiao/cryptoSchoolProject.git">https://github.com/ShenTiao/cryptoSchoolProject.git</a></p>
<a id="more"></a>

<h2 id="依赖"><a href="#依赖" class="headerlink" title="依赖"></a>依赖</h2><h3 id="Crypto"><a href="#Crypto" class="headerlink" title="Crypto++"></a>Crypto++</h3><p>Crypto++ 库是开源的 C++ 数据加密算法库，支持如下算法：RSA、MD5、DES、AES、SHA-256 等等，其中对于加密有对称加密和非对称加密。本实验通过 Cryto++ 库对字符串进行 MD5 校验，并用 AES 加密和解密。</p>
<p><a target="_blank" rel="noopener" href="https://cryptopp.com/">官网</a> <a target="_blank" rel="noopener" href="https://cryptopp.com/docs/ref/">手册</a> <a target="_blank" rel="noopener" href="https://www.cryptopp.com/wiki">wiki及代码示例</a></p>
<h4 id="安装依赖库"><a href="#安装依赖库" class="headerlink" title="安装依赖库"></a>安装依赖库</h4><p>环境：Windows 10 64bit，VS2019。</p>
<p>首先官网Download-Release Notes下载最新压缩包。</p>
<p>下载后解压缩，找到解决方案cryptlib.sln，单独对cryplib进行生成：</p>
<p><img src="https://s2.loli.net/2021/12/06/2R7Lig8oeplqjAs.png" alt="image-20211206170314034"></p>
<p>配置Release或者Debug或者两者都在x64环境下进行生成，可以在根目录x64/Output/Release下看到已经生成的lib库(以release为例)。</p>
<h4 id="建立SDK"><a href="#建立SDK" class="headerlink" title="建立SDK"></a>建立SDK</h4><p>建立一个目录CryptoPP，这里以C:\Program Files\CryptoPP为例，目录下新建目录include和lib，将生成好的lib库放在lib目录下：lib\Release。将解压缩的源文件所有cpp与h文件放置在include目录下。</p>
<p>在VS2019新建一个项目，修改项目配置：</p>
<p><img src="https://s2.loli.net/2021/12/06/g8PNbseVpDaEqF4.png" alt="image-20211206170814097"></p>
<p>包含目录即刚刚创建的include文件目录，库目录即lib目录。注意：</p>
<p><img src="https://s2.loli.net/2021/12/06/o93iwY4RUHyqS5v.png" alt="image-20211206170900318"></p>
<p>将运行库切换成/MT模式，链接器配置：</p>
<p><img src="https://s2.loli.net/2021/12/06/ILkiNmDwXy7RZPY.png" alt="image-20211206171045887"></p>
<p>否则链接失败。</p>
<h3 id="pybind11"><a href="#pybind11" class="headerlink" title="pybind11"></a>pybind11</h3><p><a target="_blank" rel="noopener" href="https://github.com/pybind/pybind11">github</a>    <a target="_blank" rel="noopener" href="https://pybind11.readthedocs.io/en/stable/">文档</a>    </p>
<p><strong>pybind11</strong>是一个轻量级的header-only库，它在 Python 中公开 C++ 类型，反之亦然，主要用于创建现有 C++ 代码的 Python 绑定。</p>
<p>核心特性：</p>
<p><img src="https://s2.loli.net/2021/12/06/ZQMfBw9J1kzj8XK.png" alt="image-20211206171313554"></p>
<p>pybind11可以很好地将C++代码打包成dll库，windows上的pyd文件来导入python代码。</p>
<p>安装pybind11过程与crypto++类似，不同的是pybind11是header-only文件，只需要配置包含目录和库目录与链接依赖项，同时python本身的lib文件与include路径也需要同样添加进去。</p>
<h3 id="第一段测试代码"><a href="#第一段测试代码" class="headerlink" title="第一段测试代码"></a>第一段测试代码</h3><h4 id="C"><a href="#C" class="headerlink" title="C++"></a>C++</h4><p>打包一段简单的MD5校验代码：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;pybind11/pybind11.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;md5.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;hex.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;files.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;osrng.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;filters.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;default.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> _CRYPTO_UTIL_H_</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> CRYPTOPP_ENABLE_NAMESPACE_WEAK 1</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> py = pybind11;</span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> CryptoPP;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span>&amp; <span class="title">retMD5</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span>&amp; data)</span> </span>&#123;</span><br><span class="line">	<span class="built_in">std</span>::<span class="built_in">string</span> digest;</span><br><span class="line">	Weak1::MD5 md5;</span><br><span class="line">	StringSource(data, <span class="literal">true</span>, <span class="keyword">new</span> HashFilter(md5, <span class="keyword">new</span> HexEncoder(<span class="keyword">new</span> StringSink(digest))));</span><br><span class="line">	<span class="keyword">return</span> digest;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">PYBIND11_MODULE(pycryptodll, m) &#123;</span><br><span class="line">	m.def(<span class="string">&quot;retMD5&quot;</span>, &amp;retMD5, <span class="string">&quot;return the MD5 value&quot;</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>编译提示：</p>
<p><code>You may be using a weak algorithm that has been retained for backwards compatibility. Please &#39;#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1&#39; before including this .h file and prepend the class name with &#39;Weak::&#39; to remove this warning.</code></p>
<p>使用向后兼容的弱算法需要添加宏：</p>
<p><code>#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1&#39;</code></p>
<p>注意22行<code>pycryptodll</code>处内容需要与项目同名，否则python解释器报错。</p>
<p><code>PYBIND11_MODULE()</code>宏创建了一个函数，当<code>import</code>从 Python 中发出语句时将调用该函数 。模块名称 ( <code>example</code>) 作为第一个宏参数给出（不应包含在引号中）。第二个参数 ( <code>m</code>) 定义了一个类型变量，<code>py::module_</code>它是创建绑定的主要接口。该方法module_::def() 生成将<code>add()</code>函数公开给 Python 的绑定代码。</p>
<h4 id="Python运行"><a href="#Python运行" class="headerlink" title="Python运行"></a>Python运行</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> pycryptodll</span><br><span class="line">print(m.retMD5(<span class="string">&quot;123131&quot;</span>))</span><br></pre></td></tr></table></figure>

<p>将pyd文件与py文件放在同目录下，输入以上代码即可调用函数。</p>
<h1 id="加密部分"><a href="#加密部分" class="headerlink" title="加密部分"></a>加密部分</h1><h2 id="对称加密算法部分"><a href="#对称加密算法部分" class="headerlink" title="对称加密算法部分"></a>对称加密算法部分</h2><h3 id="AES-CBC-mode"><a href="#AES-CBC-mode" class="headerlink" title="AES(CBC mode)"></a>AES(CBC mode)</h3><p>AES 采用的是对称加密，在密码学中又称 Rijndael 加密法，是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的 DES ，已经被多方分析且广为全世界所使用。 本次使用CBC模式，密码分组链接模式（CBC模式）：这种模式是先将明文切分成若干小段，然后每一小段与初始块或者上一段的密文段进行异或运算后，再与密钥进行加密。</p>
<p>加密流程图：</p>
<p><img src="https://s2.loli.net/2021/12/07/Ou7JMUXEsKTpZ8I.png" alt="image-20211207170621804"></p>
<p>CBC模式:</p>
<p><img src="https://s2.loli.net/2021/12/07/12ETvCjLok9aRbn.png" alt="image-20211207171108714"></p>
<p>AES密钥长度要求：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">enum</span> AESKeyLength</span><br><span class="line">&#123;</span><br><span class="line">    AES_KEY_LENGTH_16 = <span class="number">16</span>, AES_KEY_LENGTH_24 = <span class="number">24</span>, AES_KEY_LENGTH_32 = <span class="number">32</span> </span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>判断密钥长度是否满足：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (inData.empty() || Key.empty()) <span class="comment">// 判断待加密的字符串或者密钥是否为空</span></span><br><span class="line">    &#123;</span><br><span class="line">        errMsg = <span class="string">&quot;indata or key is empty!!&quot;</span>;</span><br><span class="line">        <span class="keyword">return</span> errMsg;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="keyword">unsigned</span> <span class="keyword">int</span> iKeyLen = Key.length();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (iKeyLen != AES_KEY_LENGTH_16 &amp;&amp; iKeyLen != AES_KEY_LENGTH_24  <span class="comment">//判断密钥的长度是否符合要求</span></span><br><span class="line">        &amp;&amp; iKeyLen != AES_KEY_LENGTH_32)</span><br><span class="line">    &#123;</span><br><span class="line">        errMsg = <span class="string">&quot;aes key invalid!!&quot;</span>;</span><br><span class="line">        <span class="keyword">return</span> errMsg;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p>MD5生成密钥必定满足32字节：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//加密密钥key:MD5生成32字节密钥</span></span><br><span class="line"><span class="function"><span class="keyword">const</span> <span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">encryAeskey</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span>&amp; strKey)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">const</span> <span class="built_in">std</span>::<span class="built_in">string</span> Key = retMD5(strKey);</span><br><span class="line">    <span class="keyword">return</span> Key;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>生成密文：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">try</span></span><br><span class="line">    &#123;</span><br><span class="line">        CBC_Mode&lt;AES&gt;::Encryption e;  <span class="comment">//CBC 模式加密</span></span><br><span class="line">        e.SetKeyWithIV((byte*)Key.c_str(), iKeyLen, iv);</span><br><span class="line">        <span class="comment">//加密的关键， outData 就是加密后的数据</span></span><br><span class="line">        <span class="function">StringSource <span class="title">ss</span><span class="params">(inData, <span class="literal">true</span>, <span class="keyword">new</span> StreamTransformationFilter(e, <span class="keyword">new</span> StringSink(outData)))</span></span>;    </span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">catch</span> (<span class="keyword">const</span> CryptoPP::Exception&amp; e)</span><br><span class="line">    &#123;</span><br><span class="line">        errMsg = <span class="string">&quot;Encryptor throw exception!!&quot;</span>;</span><br><span class="line">        <span class="keyword">return</span> errMsg;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p>接口函数：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//将输入Key经过MD5加密生成的32字节密钥，返回密钥值，</span></span><br><span class="line"><span class="function"><span class="keyword">const</span> <span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">encryAeskey</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span>&amp; strKey)</span> </span></span><br><span class="line"><span class="function"> </span></span><br><span class="line"><span class="function"><span class="comment">//AES加密函数，inData为明文，strKey为MD5加密前输入的key CBC下iv，返回加密字符串</span></span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">encrypt4aes</span><span class="params">(<span class="keyword">const</span> <span class="built_in">std</span>::<span class="built_in">string</span>&amp; inData,<span class="built_in">std</span>::<span class="built_in">string</span>&amp; strKey,<span class="built_in">std</span>::<span class="built_in">string</span>&amp; iv)</span></span></span><br><span class="line"><span class="function"><span class="comment">//AES解密函数 inData密文 strKey解密密钥 CBC下iv，返回解密字符串</span></span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">decrypt4aes</span><span class="params">(<span class="keyword">const</span> <span class="built_in">std</span>::<span class="built_in">string</span>&amp; inData, <span class="keyword">const</span> <span class="built_in">std</span>::<span class="built_in">string</span>&amp; strKey,<span class="built_in">std</span>::<span class="built_in">string</span>&amp; iv)</span></span></span><br></pre></td></tr></table></figure>



<h3 id="3DES-CBC-mode"><a href="#3DES-CBC-mode" class="headerlink" title="3DES(CBC mode)"></a>3DES(CBC mode)</h3><p>DES 使用一个 56 位的密钥以及附加的 8 位奇偶校验位，产生最大 64 位的分组大小。这是一个迭代的分组密码，使用称为 Feistel 的技术，其中将加密的文本块分成两半。使用子密钥对其中一半应用循环功能，然后将输出与另一半进行“异或”运算；接着交换这两半，这一过程会继续下去，但最后一个循环不交换。DES 使用 16 个循环，使用异或，置换，代换，移位操作四种基本运算。</p>
<p>TripleDES,是对纯文本数据的DES算法的多重应用，以增加原有DES算法的安全性。顾名思义，DES算法被应用了3次。TripleDES有两种变体:第一种是两个key;第二个是三个key。2-key TDEA提供大约80位的安全性，而3-key TDEA提供大约112位的安全性。相反，AES提供的最低安全级别为128。</p>
<p>本次实现2 Key Triple DES:</p>
<p>单次DES加密流程图：<img src="https://s2.loli.net/2021/12/08/VfpBGEvOU4dyZtr.png" alt="image-20211208164432707"></p>
<p><strong>上图左半部分描述了明文加密成密文的三个阶段。</strong></p>
<p>　　1、64位的明文经初始置换（IP）而重新排列。</p>
<p>　　2、进行16轮的置换和转换（基于Feistel结构）。</p>
<p>　　3、再做一次置换（IP-1，与初始置换互逆）。</p>
<p><strong>加密过程与解密过程基本一致。</strong></p>
<p><strong>上图右半部分是56位密钥的操作过程。</strong></p>
<p>　　1、密钥先做一个置换。</p>
<p>　　2、再做16次包含循环左移和置换的操作组合，每次都产生一个子密钥Ki。每一轮的置换操作都完全相同，但由于循环左移而使得每个子密钥不同。</p>
<p><strong>TripleDES总流程：</strong></p>
<p><img src="https://s2.loli.net/2021/12/08/89unBC1RcSaLhyg.png" alt="image-20211208171402234"></p>
<p>忽略奇偶校验位。</p>
<p>2key变体的块大小为8字节(64位)，并使用一个16字节的密钥。</p>
<p>BC模式:</p>
<p><img src="https://s2.loli.net/2021/12/07/12ETvCjLok9aRbn.png" alt="image-20211207171108714"></p>
<h2 id="流密码部分"><a href="#流密码部分" class="headerlink" title="流密码部分"></a>流密码部分</h2><h3 id="RC4"><a href="#RC4" class="headerlink" title="RC4"></a>RC4</h3><p>加密流程图：</p>
<p><img src="https://s2.loli.net/2021/12/13/9WrERUSM4ZjBQLl.png" alt="image-20211213134030006"></p>
<p>RC4包括初始化算法KSA，伪随机子密码生成算法PRGA两部分，S盒长度假设为256，密钥长度可配置。</p>
<p>一般key长度为1-256，crypto++中默认为16.</p>
<p>RC4作为流密码，该密码使用 40 位到 2048 位的密钥，并且没有初始化向量(iv)。</p>
<p>注意密钥长度：</p>
<blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">key length(default): 16</span><br><span class="line">key length (min): 1</span><br><span class="line">key length (max): 256</span><br><span class="line">iv size: 0</span><br></pre></td></tr></table></figure>
</blockquote>
<h2 id="非对称加密"><a href="#非对称加密" class="headerlink" title="非对称加密"></a>非对称加密</h2><h3 id="RSA"><a href="#RSA" class="headerlink" title="RSA"></a>RSA</h3><p>crypto++库提供高级RSA加密和原始RSA加密方案。这里使用OAEP-SHA加密方案，最优非对称加密填充OAEP，OAEP对IND-CCA2是可证明安全的。由Bellare和Rogaway提出，是一种随机化的消息填充技术，而且是从消息空间到一个陷门单向置换（OWTP）定义域的一个易于求逆的变换。</p>
<p><img src="https://s2.loli.net/2021/12/29/twzLFS8pVYCKmfy.png" alt="image-20211229173627961"></p>
<p> OAEP变换是把密码学杂凑函数和一个著名对称密码算法结构结合起来构造的。OAEP构造可以看成是一个两轮Feistel密码，第一轮使用杂凑函数G，第二轮使用杂凑函数H，代替Feistel密码的“s盒函数”，但这里的两个“s盒函数”不是加密钥，而且两个半分组的大小可以不同。这里函数H即SHA。</p>
<h2 id="消息认证"><a href="#消息认证" class="headerlink" title="消息认证"></a>消息认证</h2><h3 id="MD5"><a href="#MD5" class="headerlink" title="MD5"></a>MD5</h3><p><strong>MD5信息摘要算法</strong>（英语：MD5 Message-Digest Algorithm），一种被广泛使用的散列函数可以产生出一个128位的散列值。</p>
<p>由于MD5存在弱点，难以防止碰撞攻击，不适用于安全性认证。</p>
<p>MD5算法的原理可简要的叙述为：MD5码以512位分组来处理输入的信息，且每一分组又被划分为16个32位子分组，经过了一系列的处理后，算法的输出由四个32位分组组成，将这四个32位分组级联后将生成一个128位散列值。总体流程如下图所示，每次的运算都由前一轮的128位结果值和当前的512bit值进行运算。</p>
<p>Crypto++中md5内在Weak1命名空间中，使用pipeline来获取消息摘要并验证消息完整性。</p>
<h2 id="数字签名"><a href="#数字签名" class="headerlink" title="数字签名"></a>数字签名</h2><p>使用RSA-PSS进行数字签名。</p>
<p>签名过程：</p>
<p><img src="https://s2.loli.net/2021/12/22/Ccnq5ymxolKSWwe.png" alt="image-20211222155820581"></p>
<p>需要输入待编码的消息内容和emBits比RSA模数n位长度小的值，输出em编码之后的内容。</p>
<p>填充1paddding1十六进制字符串00 00·····,填充2如图。</p>
<p>加盐salt一组伪随机数。</p>
<blockquote>
<p>编码过程有如下步骤：</p>
<ol>
<li>生成消息M 的Hash值，mHash = Hash(M)</li>
<li>生成伪随机字节串作为盐，得到M’ = padding1 || mHash || salt 的数据块</li>
<li>生成M’ 的Hash值，H = Hash(M’)</li>
<li>构造数据块DB = padding2 || salt</li>
<li>计算H 的MGF值：dbMask = MGF(H, emLen - hLen - 1)</li>
<li>计算maskedDB = DB xor dbMask</li>
<li>将maskedDB 的最左8emLen - emBits设为0</li>
<li>EM = maskedDB || H || BC</li>
</ol>
</blockquote>
<p>这里哈希使用SHA256，公钥私钥以文件形式保存，读取。</p>
<h2 id="DH认证协议"><a href="#DH认证协议" class="headerlink" title="DH认证协议"></a>DH认证协议</h2><p>Diffie-Hellman是一种密钥协商算法，它允许两方建立安全的通信通道。最初的 Diffie-Hellman 是一种匿名协议，这意味着它没有经过身份验证，因此容易受到中间人攻击。Crypto++ 通过<code>DH</code>类公开未经身份验证的协议。对原始 Diffie-Hellman 的扩展包括身份验证，它强化了交换协议以抵御许多中间人攻击。Diffie-Hellman 的认证版本通常称为统一 Diffie-Hellman。Crypto++ 通过其<code>DH2</code>类提供统一的 Diffie-Hellman 。</p>
<p>注意，这个密钥交换协议/算法只能用于密钥的交换，而不能进行消息的加密和解密。双方确定要用的密钥后，要使用其他对称密钥操作加密算法实现加密和解密消息。</p>
<p><img src="https://s2.loli.net/2021/12/31/Xz3UL47ZMiJmhpF.png" alt="image-20211231163007834"></p>
<h2 id="接口部分"><a href="#接口部分" class="headerlink" title="接口部分"></a>接口部分</h2><p>c++ dll打包接口：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">enAffine</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span> inData,<span class="keyword">int</span> addKey,<span class="keyword">int</span> mulKey)</span> </span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">deAffine</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span> inData, <span class="keyword">int</span> addKey, <span class="keyword">int</span> mulKey)</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">randomARC4key</span><span class="params">(<span class="keyword">int</span> len)</span></span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">encryRC4</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span>&amp; inData, <span class="built_in">std</span>::<span class="built_in">string</span>&amp; strKey, <span class="keyword">int</span> len)</span></span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">decryRC4</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span>&amp; inData, <span class="built_in">std</span>::<span class="built_in">string</span>&amp; strKey, <span class="keyword">int</span> len)</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">enmsgMD5</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span>&amp; msg)</span></span></span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">checkmsgMD5</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span>&amp; digest, <span class="built_in">std</span>::<span class="built_in">string</span>&amp; msg)</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">randomDesKey</span><span class="params">()</span></span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">randomIv</span><span class="params">()</span></span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span>	<span class="title">encrypt3des</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span>&amp; inData, <span class="built_in">std</span>::<span class="built_in">string</span>&amp; strKey, <span class="built_in">std</span>::<span class="built_in">string</span>&amp; eniv)</span></span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">decrypt3des</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span>&amp; inData, <span class="built_in">std</span>::<span class="built_in">string</span>&amp; strKey, <span class="built_in">std</span>::<span class="built_in">string</span>&amp; eniv)</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">getRsaKey</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span> pubfilename,<span class="built_in">std</span>::<span class="built_in">string</span> prifilename)</span> </span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">getRsaSignature</span><span class="params">(<span class="keyword">const</span> <span class="built_in">std</span>::<span class="built_in">string</span>&amp; prifilename,<span class="keyword">const</span> <span class="built_in">std</span>::<span class="built_in">string</span>&amp; msg)</span></span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">checkRsaSigature</span><span class="params">(<span class="keyword">const</span> <span class="built_in">std</span>::<span class="built_in">string</span>&amp; pubfilename, <span class="keyword">const</span> <span class="built_in">std</span>::<span class="built_in">string</span>&amp; signature,<span class="keyword">const</span> <span class="built_in">std</span>::<span class="built_in">string</span>&amp; msg)</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">getRSAOAEPkey</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span> pubfilename, <span class="built_in">std</span>::<span class="built_in">string</span> prifilename)</span></span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">encryRSAOAEP</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span> pubfilename, <span class="built_in">std</span>::<span class="built_in">string</span> plain)</span></span></span><br><span class="line"><span class="function"><span class="built_in">std</span>::<span class="built_in">string</span> <span class="title">decryRSAOAEP</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span> prifilename, <span class="built_in">std</span>::<span class="built_in">string</span> cipher)</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">    </span></span><br></pre></td></tr></table></figure>

<p>pybind11打包接口：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//Affine</span></span><br><span class="line">   m.def(<span class="string">&quot;encryAffine&quot;</span>, &amp;enAffine);</span><br><span class="line">   m.def(<span class="string">&quot;decryAffine&quot;</span>, &amp;deAffine);</span><br><span class="line">   <span class="comment">//ARC4</span></span><br><span class="line">   m.def(<span class="string">&quot;randomARC4key)&quot;</span>, &amp;randomARC4key);</span><br><span class="line">   m.def(<span class="string">&quot;encryRC4&quot;</span>, &amp;encryRC4);</span><br><span class="line">   m.def(<span class="string">&quot;decryRC4&quot;</span>, &amp;decryRC4);</span><br><span class="line">   <span class="comment">//MD5</span></span><br><span class="line">   m.def(<span class="string">&quot;enmsgMD5&quot;</span>, &amp;enmsgMD5);</span><br><span class="line">   m.def(<span class="string">&quot;checkmsgMD5&quot;</span>, &amp;checkmsgMD5);</span><br><span class="line">   <span class="comment">//DES</span></span><br><span class="line">   m.def(<span class="string">&quot;randomDesKey&quot;</span>, &amp;randomDesKey);</span><br><span class="line">   m.def(<span class="string">&quot;randomIv&quot;</span>, &amp;randomIv);</span><br><span class="line">   m.def(<span class="string">&quot;encrypt3des&quot;</span>, &amp;encrypt3des);</span><br><span class="line">   m.def(<span class="string">&quot;decrypt3des&quot;</span>, &amp;decrypt3des);</span><br><span class="line">   <span class="comment">//rsa pss签名</span></span><br><span class="line">   m.def(<span class="string">&quot;getRsaKey&quot;</span>, &amp;getRsaKey);</span><br><span class="line">   m.def(<span class="string">&quot;getRsaSignature&quot;</span>, &amp;getRsaSignature);</span><br><span class="line">   m.def(<span class="string">&quot;checkRsaSigature&quot;</span>, &amp;checkRsaSigature);</span><br><span class="line">   <span class="comment">//rsa oaep加密</span></span><br><span class="line">   m.def(<span class="string">&quot;getRSAOAEPkey&quot;</span>, &amp;getRSAOAEPkey);</span><br><span class="line">   m.def(<span class="string">&quot;encryRSAOAEP&quot;</span>, &amp;encryRSAOAEP);</span><br><span class="line">   m.def(<span class="string">&quot;decryRSAOAEP&quot;</span>, &amp;decryRSAOAEP);</span><br></pre></td></tr></table></figure>



<h1 id="界面部分"><a href="#界面部分" class="headerlink" title="界面部分"></a>界面部分</h1><h3 id="界面效果"><a href="#界面效果" class="headerlink" title="界面效果"></a>界面效果</h3><p><img src="https://s2.loli.net/2022/01/08/Goa2fYiTd9VLr7K.png" alt="image-20220108144322752"></p>
<p><img src="https://s2.loli.net/2022/01/08/KvMFrj5aD3lgE46.png" alt="image-20220108144331220"></p>
<p><img src="https://s2.loli.net/2022/01/08/IwQj7EuyFoqTrfU.png" alt="image-20220108144340061"></p>
<h3 id="界面实现"><a href="#界面实现" class="headerlink" title="界面实现"></a>界面实现</h3><p>使用PyQt5实现，其中DH部分使用cryptography库简单实现。</p>
<p>使用Qt Designer画出界面后，使用uic工具生成py代码。</p>
<p>信号绑定：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#信号绑定</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">init</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="comment">#TAB1</span></span><br><span class="line">        self.encryChooseBox.currentIndexChanged.connect(self.changeMethodStr)</span><br><span class="line">        self.inputClearPush.clicked.connect(self.clearInputTextBox)</span><br><span class="line">        self.outputClearPush.clicked.connect(self.clearOutputTextBox)</span><br><span class="line">        self.enCryPush.clicked.connect(self.enCryptAccess)</span><br><span class="line">        self.affineArgA.textChanged.connect(self.changeAffineArgsA)</span><br><span class="line">        self.affineArgP.textChanged.connect(self.changeAffineArgsP)</span><br><span class="line">        self.arc4KeyLen.textChanged.connect(self.changeARC4KeyLen)</span><br><span class="line">        self.pubkeyFileName.textChanged.connect(self.changeRsaPubFileName)</span><br><span class="line">        self.prikeyFileName.textChanged.connect(self.changeRsaPriFileName)</span><br><span class="line">        <span class="comment">#TAB2</span></span><br><span class="line">        self.decryChooseBox.currentIndexChanged.connect(self.changeDeMethodStr)</span><br><span class="line">        self.inputClearPush_Tab2.clicked.connect(self.clearInputTextBox_2)</span><br><span class="line">        self.outputClearPush_Tab2.clicked.connect(self.clearOutputTextBox_2)</span><br><span class="line">        self.keyClearPush.clicked.connect(self.clearKeyPut)</span><br><span class="line">        self.deCryPush.clicked.connect(self.deCryptAccess)</span><br><span class="line">        self.affineArgA_Tab2.textChanged.connect(self.changeAffineArgsA_2)</span><br><span class="line">        self.affineArgP_Tab2.textChanged.connect(self.changeAffineArgsP_2)</span><br><span class="line">        self.arc4KeyLen_Tab2.textChanged.connect(self.changeARC4KeyLen_2)</span><br><span class="line">        self.pubkeyFileName_Tab2.textChanged.connect(self.changeRsaPubFileName_2)</span><br><span class="line">        self.prikeyFileName_Tab2.textChanged.connect(self.changeRsaPriFileName_2)</span><br><span class="line">        <span class="comment">#TAB3</span></span><br><span class="line">        self.clientIpText.textChanged.connect(self.changeClientIp)</span><br><span class="line">        self.clientPortText.textChanged.connect(self.changeClientPort)</span><br><span class="line">        self.getLocalIpPush.clicked.connect(self.getLocalIp)</span><br><span class="line">        self.openLinkPush.clicked.connect(self.openLink)</span><br><span class="line">        self.closeLinkPush.clicked.connect(self.closeLink)</span><br><span class="line">        self.clearDhInput.clicked.connect(self.clearDhin)</span><br><span class="line">        self.clearDhOutput.clicked.connect(self.clearDhout)</span><br><span class="line">        self.clearMsgOutput.clicked.connect(self.clearMsgout)</span><br><span class="line">        self.signalLinkWrite.connect(self.linkMsgPrint)</span><br><span class="line">        self.sendMsgPush.clicked.connect(self.sendMsg)</span><br><span class="line">        self.serverPubKeyPush.clicked.connect(self.getServerPubKey)</span><br><span class="line">        self.sendServerPubkey.clicked.connect(self.passServerPubKey)</span><br><span class="line">        self.sendClientPubPara.clicked.connect(self.sendPubPara)</span><br><span class="line">        self.creServerSharedKey.clicked.connect(self.getSeverSharedKey)</span><br><span class="line">        self.waitClientPubKey.textChanged.connect(self.getClientPubKey)</span><br></pre></td></tr></table></figure>


    </div>
    
    
    

      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/C/" rel="tag"><i class="fa fa-tag"></i> C++</a>
              <a href="/tags/Python/" rel="tag"><i class="fa fa-tag"></i> Python</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/12/31/fuzz/" rel="prev" title="Fuzz入门&&AFL基本操作">
      <i class="fa fa-chevron-left"></i> Fuzz入门&&AFL基本操作
    </a></div>
      <div class="post-nav-item">
    <a href="/2022/01/13/jop-attack/" rel="next" title="JOP代码复用攻击的实现">
      JOP代码复用攻击的实现 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Crypto-%E5%AE%9E%E7%8E%B0%E5%B8%B8%E7%94%A8%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95"><span class="nav-number">1.</span> <span class="nav-text">Crypto++实现常用加密算法</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BE%9D%E8%B5%96"><span class="nav-number">1.1.</span> <span class="nav-text">依赖</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Crypto"><span class="nav-number">1.1.1.</span> <span class="nav-text">Crypto++</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%AE%89%E8%A3%85%E4%BE%9D%E8%B5%96%E5%BA%93"><span class="nav-number">1.1.1.1.</span> <span class="nav-text">安装依赖库</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%BB%BA%E7%AB%8BSDK"><span class="nav-number">1.1.1.2.</span> <span class="nav-text">建立SDK</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#pybind11"><span class="nav-number">1.1.2.</span> <span class="nav-text">pybind11</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%AC%AC%E4%B8%80%E6%AE%B5%E6%B5%8B%E8%AF%95%E4%BB%A3%E7%A0%81"><span class="nav-number">1.1.3.</span> <span class="nav-text">第一段测试代码</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#C"><span class="nav-number">1.1.3.1.</span> <span class="nav-text">C++</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Python%E8%BF%90%E8%A1%8C"><span class="nav-number">1.1.3.2.</span> <span class="nav-text">Python运行</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%8A%A0%E5%AF%86%E9%83%A8%E5%88%86"><span class="nav-number">2.</span> <span class="nav-text">加密部分</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AF%B9%E7%A7%B0%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95%E9%83%A8%E5%88%86"><span class="nav-number">2.1.</span> <span class="nav-text">对称加密算法部分</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#AES-CBC-mode"><span class="nav-number">2.1.1.</span> <span class="nav-text">AES(CBC mode)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3DES-CBC-mode"><span class="nav-number">2.1.2.</span> <span class="nav-text">3DES(CBC mode)</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B5%81%E5%AF%86%E7%A0%81%E9%83%A8%E5%88%86"><span class="nav-number">2.2.</span> <span class="nav-text">流密码部分</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#RC4"><span class="nav-number">2.2.1.</span> <span class="nav-text">RC4</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%9D%9E%E5%AF%B9%E7%A7%B0%E5%8A%A0%E5%AF%86"><span class="nav-number">2.3.</span> <span class="nav-text">非对称加密</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#RSA"><span class="nav-number">2.3.1.</span> <span class="nav-text">RSA</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B6%88%E6%81%AF%E8%AE%A4%E8%AF%81"><span class="nav-number">2.4.</span> <span class="nav-text">消息认证</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#MD5"><span class="nav-number">2.4.1.</span> <span class="nav-text">MD5</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%95%B0%E5%AD%97%E7%AD%BE%E5%90%8D"><span class="nav-number">2.5.</span> <span class="nav-text">数字签名</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#DH%E8%AE%A4%E8%AF%81%E5%8D%8F%E8%AE%AE"><span class="nav-number">2.6.</span> <span class="nav-text">DH认证协议</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%8E%A5%E5%8F%A3%E9%83%A8%E5%88%86"><span class="nav-number">2.7.</span> <span class="nav-text">接口部分</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%95%8C%E9%9D%A2%E9%83%A8%E5%88%86"><span class="nav-number">3.</span> <span class="nav-text">界面部分</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%95%8C%E9%9D%A2%E6%95%88%E6%9E%9C"><span class="nav-number">3.0.1.</span> <span class="nav-text">界面效果</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%95%8C%E9%9D%A2%E5%AE%9E%E7%8E%B0"><span class="nav-number">3.0.2.</span> <span class="nav-text">界面实现</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Sekla"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Sekla</p>
  <div class="site-description" itemprop="description">Sekla</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">100</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/ShenTiao" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;ShenTiao" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:584892986@qq.com" title="E-Mail → mailto:584892986@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



      </div>

      <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=1416875904&auto=0&height=66"></iframe>
      
    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Sekla</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">288k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">4:22</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script size="300" alpha="0.6" zIndex="-1" src="/lib/canvas-ribbon/canvas-ribbon.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  
      

<script>
  if (typeof MathJax === 'undefined') {
    window.MathJax = {
      loader: {
        source: {
          '[tex]/amsCd': '[tex]/amscd',
          '[tex]/AMScd': '[tex]/amscd'
        }
      },
      tex: {
        inlineMath: {'[+]': [['$', '$']]},
        tags: 'ams'
      },
      options: {
        renderActions: {
          findScript: [10, doc => {
            document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
              const display = !!node.type.match(/; *mode=display/);
              const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
              const text = document.createTextNode('');
              node.parentNode.replaceChild(text, node);
              math.start = {node: text, delim: '', n: 0};
              math.end = {node: text, delim: '', n: 0};
              doc.math.push(math);
            });
          }, '', false],
          insertedScript: [200, () => {
            document.querySelectorAll('mjx-container').forEach(node => {
              let target = node.parentNode;
              if (target.nodeName.toLowerCase() === 'li') {
                target.parentNode.classList.add('has-jax');
              }
            });
          }, '', false]
        }
      }
    };
    (function () {
      var script = document.createElement('script');
      script.src = '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
      script.defer = true;
      document.head.appendChild(script);
    })();
  } else {
    MathJax.startup.document.state(0);
    MathJax.texReset();
    MathJax.typeset();
  }
</script>

    

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"left","width":250,"height":500},"mobile":{"show":false},"react":{"opacity":0.9},"log":false});</script></body>
</html>

<script type="text/javascript" src="/js/src/love.js"></script>
